﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MailClient.Data;
using MailClient;
using MailClient.Handlers;
using System.Data;

namespace MailClient.Commands
{
    /// <summary>
    /// Use to subscribe to projects and thier notifications
    /// </summary>
    class subscribe : Query, ICommand, IDisposable
    {
        private Handlers.designator _designator;
        public Handlers.designator Designator
        {
            get { return _designator; }
            set { _designator = Designator; }
        }
        public subscribe(Command com, string[] query) { _query = query; }

        private string[] _query;


        private MailMessage _msg;

        public MailMessage MsgReply
        {
            get { return _msg; }
        }

        public void Dispose() { }

        public bool CommitData() { return false; }

        public bool Command(Job job)
        {bool flag = false;
            foreach (string s in _query)
            {
                
                if (job.Type == JobType.Store)
                {
                    DataRow[] rows = TryQuery(job.GetJobType(s), s);
                    
                    // i now have an array of stores
                    foreach (DataRow row in rows)
                    {
                        string fields = "str_num= ";
                        fields += "'" + row["str_num"].ToString() + "'";
                        

                        DataRow[] tridentstores = ScheduleData.Tables["trident"].Select(fields);
                        foreach (DataRow date in tridentstores)
                        {
                            // add sender's email to the mailing list
                            
                        }
                    }
                    flag = true;
                    return flag;
                }

            }
            return flag;
        }
        private void InsertorUpdateRow()
        {/*
            DataRow[] stores = Schedules(storenum.ToString(), "*", StoreType.ToString(), ProjectStatus.Active);
            // for now get only the first returned row
            DataRow store = stores[0];

            string id = store["trident_id"].ToString();
            DataTable merchtable = ScheduleData.Tables["merch"];
            DataRow[] merchrows = merchtable.Select(string.Format("trident_id = '{0}'", id));
            if (merchrows.Length == 0)
            {
                DataRow newrow = merchtable.NewRow();
                newrow["trident_id"] = id;
                FillRow(ref newrow);
                merchtable.Rows.Add(newrow);
            }
            else
            {
                DataRow merchrow = merchrows[0];
                FillRow(ref merchrow);
            }*/
        }
        private void FillRow(ref DataRow row)
        {
           
        }
    }
}
